﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace carportal
{
    public partial class AdvancedSearch : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                if (CheckBoxCarType1Limo.Checked ||
                    CheckBoxCarType2Small.Checked ||
                    CheckBoxCarType3Estate.Checked ||
                    CheckBoxCarType4Van.Checked ||
                    CheckBoxCarType5Offroad.Checked ||
                    CheckBoxCarType6Cabrio.Checked ||
                    CheckBoxCarType7Sport.Checked ||
                    CheckBoxCarType8Other.Checked)
                {
                    RadioButtonCartype.Checked = true;
                }
                else { RadioButtonCarTypeAll.Checked = true; }
            }
        }

        protected void RadioButtonCarTypeAll_CheckedChanged(object sender, EventArgs e)
        {
            if (RadioButtonCarTypeAll.Checked == true)
            {
                CheckBoxCarType1Limo.Checked = false;
                CheckBoxCarType2Small.Checked = false;
                CheckBoxCarType3Estate.Checked = false;
                CheckBoxCarType4Van.Checked = false;
                CheckBoxCarType5Offroad.Checked = false;
                CheckBoxCarType6Cabrio.Checked = false;
                CheckBoxCarType7Sport.Checked = false;
                CheckBoxCarType8Other.Checked = false;

            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (RadioButtonCarTypeAll.Checked)
                SqlDataSourceSearchCar.InsertParameters["car_type"].DefaultValue = "-1";
            SqlDataSourceSearchCar.Insert();
            Server.Transfer("/search.aspx");
        }

        protected void SqlDataSourceSearchCar_Inserted(object sender, SqlDataSourceStatusEventArgs e)
        {
            Session["SearchID"] = e.Command.Parameters["@SearchID"].Value.ToString();
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            if (RadioButtonCarTypeAll.Checked)
                SqlDataSourceSearchCar.InsertParameters["car_type"].DefaultValue = "-1";
            SqlDataSourceSearchCar.Insert();
            Response.Redirect("/search.aspx");
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            if (RadioButtonCarTypeAll.Checked)
                SqlDataSourceSearchCar.InsertParameters["car_type"].DefaultValue = "-1";
            SqlDataSourceSearchCar.Insert();
            Response.Redirect("/search.aspx");
        }
    }
}